package com.jzhao.jpre.security;

import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;

/**
 * @author  Nameless
 */
public class ProcessingPool {
	private final static int DEFAULT_MAX_POOL_SIZE = 100;
	private static PooledExecutor pool;

	public static PooledExecutor getPool() {
		if (pool == null) {
			pool = new PooledExecutor();
			pool.setMaximumPoolSize(DEFAULT_MAX_POOL_SIZE);
			pool.setMinimumPoolSize(1);
			pool.setKeepAliveTime(1000 * 60 * 5);
			pool.abortWhenBlocked();
			pool.createThreads(DEFAULT_MAX_POOL_SIZE);
		}
		return pool;
	}

	public static void clear() {
		if (pool != null) {
			pool.shutdownAfterProcessingCurrentlyQueuedTasks();
			pool = null;
		}
	}
}
